
//
// 110703 - AH - Created.
//

package org.soekrat.gui.swing.textcloud;

import java.awt.Color;

/**
 * <p>
 *   Default
 *   {@link CloudText} implementation.
 * </p>
 * @author Arne Halvorsen (AH)
 */
public class DefaultCloudText implements CloudText
{
  private final String m_text;
  
  private final Color m_color;
  
  private final float m_weight;
  
  /**
   * <p>
   *   Constructor.
   * </p>
   * <p>
   *   Color will be black and weight will be {@code 0.5}.
   * </p>
   * @param t Text to render.
   */
  public DefaultCloudText(String t){ this(t, Color.BLACK, 0.5f); }
  
  /**
   * <p>
   *   Constructor.
   * </p>
   * <p>
   *   Weight will be {@code 0.5}.
   * </p>
   * @param t Text to render.
   * @param c Color to render text in. 
   */
  public DefaultCloudText(String t, Color c){ this(t, c, 0.5f); }
  
  /**
   * <p>
   *   Constructor.
   * </p>
   * <p>
   *   Color will be black.
   * </p>
   * @param t Text to render.
   * @param w Weight of text. 
   */
  public DefaultCloudText(String t, float w){ this(t, Color.BLACK, w); }
  
  /**
   * <p>
   *   Constructor.
   * </p>
   * @param t Text to render.
   * @param c Color to render text in.
   * @param w Weight of text.
   * @throws IllegalArgumentException If {@code text} is the empty string or
   *         {@code weight<=0.0 || weight>1.0}.
   */
  public DefaultCloudText(String t, Color c, float w)
  {
    if (t==null)
    {
      throw new NullPointerException("text");
    }
    
    t=t.trim();
    if (t.length()==0)
    {
      throw new IllegalArgumentException("text is the empty string");
    }
    
    if (c==null)
    {
      throw new NullPointerException("color");
    }
    if (w<=0.0f)
    {
      throw new IllegalArgumentException("weight<=0.0 : "+w);
    }
    if (w>1.0f)
    {
      throw new IllegalArgumentException("weight>1.0 : "+w);
    }
    
    m_text=t;
    m_color=c;
    m_weight=w;
  }

  // Specified in CloudText.
  public String getText(){ return m_text; }

  // Specified in CloudText.
  public float getWeight(){ return m_weight; }
  
  // Specified in CloudText.
  public Color getColor(){ return m_color; }

  @Override
  public String toString() 
  {
    StringBuilder sb=new StringBuilder();
    sb.append("text=").append(m_text).append(", color=").append(m_color)
      .append(", weight=").append(m_weight);
    return sb.toString();
  }
  
}
